/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Connection;

/**
 *
 * @author Quang
 */
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import java.sql.*;
import javax.swing.JOptionPane;
public class MyConnect {
    public static Connection iconnect = null;
    public String sqlserver,user,pass,databaseName;
    public int ports;
    public boolean a = false;
    public MyConnect(String sqlserver,String user,String pass,int ports, String databaseName)
    {
        
        this.sqlserver = sqlserver;
        this.user = user;
        this.pass = pass;
        this.ports = ports;
        this.databaseName = databaseName;
        SQLServerDataSource icn = new SQLServerDataSource();
        icn.setServerName(this.sqlserver);
        icn.setUser(this.user);
        icn.setPassword(this.pass);
        icn.setPortNumber(this.ports);
        icn.setDatabaseName(this.databaseName);
        try
        {this.iconnect = icn.getConnection();a = true;}    
        catch(Exception ex)
        {JOptionPane.showMessageDialog(null,"Something wrong");a = false;}    
    }        
    
    public MyConnect()
    {
        SQLServerDataSource cn = new SQLServerDataSource();
        cn.setServerName("QUANGTDGC60289");
        cn.setUser("sa");
        cn.setPassword("tranwang");
        cn.setPortNumber(1433);
        cn.setDatabaseName("Marvell");
        try
        {this.iconnect = cn.getConnection();a = true;}
        catch(Exception ex)
        {JOptionPane.showMessageDialog(null,"Something wrong");a = false;}    
    }      
    
    public boolean checkConnect()
    {
        if(a == true)
        {return true;}    
        return false;
    }

}
